package com.zto.wk.pattern.observer;

import java.util.Enumeration;
import java.util.Vector;

/**
 * Created by wangkuan at 2019-02-11 17:30
 */
public abstract class AbstractObserved implements Observed{

    private final Vector<Observer> vector = new Vector<>();

    @Override
    public boolean add(Observer observer) {
        return vector.add(observer);
    }

    @Override
    public boolean remove(Observer observer) {
        return vector.remove(observer);
    }

    @Override
    public void notifyObservers() {
        Enumeration<Observer> elements = vector.elements();

        while (elements.hasMoreElements()) {
            elements.nextElement().callback();
        }
    }
}
